package com.mofang.ticketing.user.serve.account.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mofang.ticketing.common.core.dto.PrimaryIdDTO;
import com.mofang.ticketing.common.core.page.PageResult;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.core.urls.user.account.AccountUrl;
import com.mofang.ticketing.common.log.SystemLog;
import com.mofang.ticketing.user.serve.account.dto.request.*;
import com.mofang.ticketing.user.serve.account.dto.response.PlatformAccountListPageRespDTO;
import com.mofang.ticketing.user.serve.account.service.PlatformAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author LGC
 */
@Slf4j
@Api(tags = "平台账号管理")
@RestController
public class PlatformAccountController {

    @Resource
    private PlatformAccountService platformAccountService;

    @ApiOperation(value = "平台账号分页列表")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_LIST_PAGE)
    public Result<PageResult<PlatformAccountListPageRespDTO>> platformAccountListPage(@RequestBody @Validated PlatformAccountListPageReqDTO dto) {
        IPage<PlatformAccountListPageRespDTO> result = platformAccountService.platformAccountListPage(dto);
        return Result.page(PageResult.getPageResult(result));
    }

    @SystemLog
    @ApiOperation(value = "平台账号新增")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_ADD)
    public Result<Void> platformAccountAdd(@RequestBody @Validated PlatformAccountAddReqDTO dto) {
        platformAccountService.platformAccountAdd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台账号修改")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_UPDATE)
    public Result<Void> platformAccountUpdate(@RequestBody @Validated PlatformAccountUpdateReqDTO dto) {
        platformAccountService.platformAccountUpdate(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台账号禁用启用")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_ENABLE)
    public Result<Void> platformAccountEnable(@RequestBody @Validated PrimaryIdDTO dto) {
        platformAccountService.platformAccountEnable(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台账号重置密码")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_RESET_PWD)
    public Result<Void> platformAccountResetPwd(@RequestBody @Validated PrimaryIdDTO dto) {
        platformAccountService.platformAccountResetPwd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台账号删除")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_DEL)
    public Result<Void> platformAccountDel(@RequestBody @Validated PrimaryIdDTO dto) {
        platformAccountService.platformAccountDel(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台账号设置修改密码")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_UPDATE_PWD)
    public Result<Void> platformAccountUpdatePwd(@RequestBody @Validated AccountUpdatePwdReqDTO dto) {
        platformAccountService.platformAccountUpdatePwd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台账号设置修改手机号（账号）")
    @PostMapping(value = AccountUrl.PLATFORM_ACCOUNT_UPDATE_PHONE)
    public Result<Void> platformAccountUpdatePhone(@RequestBody @Validated AccountUpdatePhoneReqDTO dto) {
        platformAccountService.platformAccountUpdatePhone(dto);
        return Result.success();
    }
}
